﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MagicArenaFramework.GameObject.Attributes.Concrete
{
    public class CurManaAttribute : ScalarAttribute
    {
        public const UInt32 CurManaFamily=4;
        private int Max, Cur;

        public CurManaAttribute(int maxMana, int curMana) : base(CurManaFamily, curMana)
        {
            Max = maxMana;
            Cur = curMana;
        }

        void MyUpdate()
        {
            if (Cur > Max) Cur = Max;
            if (Cur < 0) die();
            ScalarAttributeHolder p = (Parent as ScalarAttributeHolder);
            // Check for Mana regen rate here
            //p.ValueFor
        }

        void die()
        {
            //TODO do something when you die, this should probably be handled elsewhere come to think of it...
        }
    }

    public class MaxManaAttribute : ScalarAttribute
    {
        public const UInt32 MaxManaFamily=5;
        public MaxManaAttribute(int maxMana) : base(MaxManaFamily, maxMana) { }
    }

    public class RegenManaAttribute : ScalarAttribute
    {
        public const UInt32 RegenManaFamily=6;
        public RegenManaAttribute(float regenPerSec) : base(RegenManaFamily, regenPerSec) 
        {
            this.UpdateDel = MyUpdate; 
        }

        void MyUpdate(float dt)
        {
            ScalarAttributeHolder holder = (Parent as ScalarAttributeHolder);
            float Mana;
            float regen;
            if (holder.ValueFor(CurManaAttribute.CurManaFamily, out Mana) && holder.ValueFor(RegenManaFamily, out regen))
            {
                Mana += regen * dt;
                holder.AddUpdateValue(CurManaAttribute.CurManaFamily, Mana);
            }
        }
    }
}

